package com.pinyougou.search.service.impl;

import com.alibaba.fastjson.JSON;
import com.pinyougou.pojo.TbItem;
import com.pinyougou.search.service.ItemSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jms.*;

import java.util.List;
import java.util.Map;

@Component
public class ItemSearchListener implements MessageListener {
    @Autowired
    private ItemSearchService itemSearchService;

    @Override
    public void onMessage(Message message) {

        TextMessage textMessage= (TextMessage) message;
        try {
            String text = textMessage.getText();
            System.out.println("监听到的消息111:"+text);
            List<TbItem> list = JSON.parseArray(text,TbItem.class);
//            for(TbItem item:list){
//                System.out.println(item.getId()+" "+item.getTitle());
//                Map specMap= JSON.parseObject(item.getSpec());//将spec字段中的json字符串转换为map
//                item.setSpecMap(specMap);//给带注解的字段赋值
//            }
            itemSearchService.importList(list);//导入
            System.out.println("成功导入到solr索引库");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
